package qeug.shsh.opplugin;

import kd.bos.context.RequestContext;
import kd.bos.exception.KDException;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.schedule.executor.AbstractTask;
import kd.bos.servicehelper.operation.DeleteServiceHelper;

import java.util.Calendar;
import java.util.Date;
import java.util.Map;

//定时任务：删除超过两年的接口日志
public class LogExpiryTask extends AbstractTask {

    private static final Log log = LogFactory.getLog(LogExpiryTask.class);
    @Override
    public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
        log.info("----执行删除两年前接口日志----");
        // 获取当前时间并计算两年前的时间
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.YEAR, -2);
        Date twoYearsAgo = calendar.getTime();

        //过滤两年前接口日志
        QFilter qFilter = new QFilter("qeug_operation_times", QCP.less_than, twoYearsAgo);
        String s = qFilter.toString();
        log.info("两年前时间："+ s);//记录执行日志

        // 执行删除
        DeleteServiceHelper.delete("qeug_interfacelog", new QFilter[]{qFilter});
    }

    @Override
    public boolean isSupportReSchedule() {
        return super.isSupportReSchedule();
    }
}
